package com.stox.client.http;

import java.util.Date;
import java.util.List;

import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpMethod;
import org.springframework.stereotype.Component;

import com.stox.client.BarClient;
import com.stox.dto.Bar;
import com.stox.dto.enumeration.SpanType;
import com.stox.dto.web.Response;

@Component
@SuppressWarnings("unchecked")
public class BarHttpClient extends AbstractHttpClient implements BarClient {

	@Override
	public List<Bar> findByScripId(Long scripId, SpanType spanType, Date start,int count) {
		return extract(getRestTemplate().exchange(getRootUrl() + "/bars?scripId="+scripId + "&spanType="+spanType.name() + "&start="+start.getTime() + "&count="+count, 
				HttpMethod.GET, null, new ParameterizedTypeReference<Response<List<Bar>>>(){}));
	}

	@Override
	public List<Bar> findByScripId(Long scripId, SpanType spanType, Date start,Date end) {
		return extract(getRestTemplate().exchange(getRootUrl() + "/bars?scripId="+scripId + "&spanType="+spanType.name() + "&start="+start.getTime() + "&end="+end.getTime(), 
				HttpMethod.GET, null, new ParameterizedTypeReference<Response<List<Bar>>>(){}));
	}
	
}
